Notebook 3: Applying classifier to h5 files¶
Load the pyecog module¶
The easiest place to place and run this notebook is from the directory downloaded from github, e.g. Pyecog-Master as the pyecog module will be found in this folder. However, if you want to run the notebook from else where on your computer you first need to make sure that python can find the pyecog module using sys.path.append(). To do this copy the following code into a cell and run it (shift+enter).
import sys
pyecog_path = '/home/jonathan/git_repos/pyecog' # replace this with the Pyecog-Master location
sys.path.append(pyecog_path)
In [1]:
# import sys
# pyecog_path = '/home/jonathan/git_repos/pyecog' # replace this with the Pyecog-Master location
# sys.path.append(pyecog_path)
In [2]:
import pyecog as pg
In [3]:
import os
In [4]:
h5_folderpath = '/media/jonathan/DATA/seizure_data/test_convert_h5'
In [6]:
clf_filepath = '/media/jonathan/DATA/seizure_data/test_clf_2017lib_gl.p'
In [7]:
clf = pg.classifier.load_classifier(clf_filepath)
/home/jonathan/anaconda3/envs/pyecog_env/lib/python3.5/site-packages/sklearn/base.py:311: UserWarning: Trying to unpickle estimator Imputer from version 0.18.1 when using version 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
/home/jonathan/anaconda3/envs/pyecog_env/lib/python3.5/site-packages/sklearn/base.py:311: UserWarning: Trying to unpickle estimator StandardScaler from version 0.18.1 when using version 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
/home/jonathan/anaconda3/envs/pyecog_env/lib/python3.5/site-packages/sklearn/base.py:311: UserWarning: Trying to unpickle estimator DecisionTreeClassifier from version 0.18.1 when using version 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
/home/jonathan/anaconda3/envs/pyecog_env/lib/python3.5/site-packages/sklearn/base.py:311: UserWarning: Trying to unpickle estimator RandomForestClassifier from version 0.18.1 when using version 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
Use classifier to predict seizures¶
convert_ndf_directory_to_h5 arguments:
- h5py_folder,
- n_cores=-1,
- timewindow=5,
- overwrite_features=False,
- gui_object=False.
In [8]:
predictions_csv = '/media/jonathan/DATA/seizure_data/test_predictions.csv'
In [9]:
clf.predict_dir(h5_folderpath,
output_csv_filename=predictions_csv)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-5ebe552e178a> in <module>()
----> 1 clf.predict_dir(h5_folderpath,
2 output_csv_filename=predictions_csv)
AttributeError: 'Classifier' object has no attribute 'predict_dir'
In [ ]: